package model

// PlayerState represents game state of player
type PlayerState struct {
	PlayerID        int             `json:"playerID"`
	Status          Status          `json:"status"`
	Progress        float64         `json:"progress"`
	PlayingPuzzleID int             `json:"playingPuzzleID"`
	GamingScore     int             `json:"gamingScore"`
	Location        *PlayerLocation `json:"location"`
}

// PlayerLocation represents current location of player
type PlayerLocation struct {
	RoomID int `json:"roomID"`
	Seat   int `json:"seat"`
}

// PlayerStateCfg use to create PlayerState
type PlayerStateCfg struct {
	PlayerID        int
	Status          Status
	Progress        float64
	PlayingPuzzleID int
	GamingScore     int
	Location        PlayerLocation
}

// NewPlayerStateByDefault new playerState with default settings
func NewPlayerStateByDefault(playerID int) *PlayerState {
	cfg := PlayerStateCfg{
		PlayerID:        playerID,
		Status:          StatusWandering,
		Progress:        0,
		PlayingPuzzleID: 0,
		GamingScore:     0,
		Location: PlayerLocation{
			RoomID: 0,
			Seat:   0,
		},
	}
	return NewPlayerState(cfg)
}

// NewPlayerState creates playerState
func NewPlayerState(cfg PlayerStateCfg) *PlayerState {
	if cfg.PlayerID == 0 {
		panic("NewPlayerState: PlayerID can't be 0")
	}
	return &PlayerState{
		PlayerID:        cfg.PlayerID,
		Status:          cfg.Status,
		Progress:        cfg.Progress,
		GamingScore:     cfg.GamingScore,
		PlayingPuzzleID: cfg.PlayingPuzzleID,
		Location:        &cfg.Location,
	}
}
